home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0106_Another FAST Uppercase.pas < prev   
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  85 lines

  1. {
  2. In SWAG9408, Jose Campione provided TXLATE5, a fast case conversion
  3. procedure.  In response to the included request for suggestions and
  4. improvements, please find attached my uppercase translation procedure,
  5. which although very similar, is approx 10-15% faster.  This is
  6. primarily achieved by using DEC CX and JNZ @Dest instead of LOOP @Dest
  7. in the conversion loop (much faster on 386/486's).
  8.  
  9. Feel free to include the source code in the next SWAG release if you
  10. wish to.
  11.  
  12. ====================================================================
  13. }
  14. UNIT XLAT;
  15.  
  16. {$S-}
  17.  
  18. INTERFACE
  19.  
  20. VAR
  21.   Upper : ARRAY[Char] OF Char; {Uppercase Translation Table}
  22. {
  23. This case translation table is initialised according to the country  
  24. code information specified in the CONFIG.SYS file (DOS 4.0+).      
  25. For older DOS versions, the standard character translations are used.
  26.  
  27. The 'Upper' array may also be accessed directly, eg: Ch := Upper['x']. 
  28. This is the fastest possible replacement for the Upcase() function. 
  29. }
  30.   PROCEDURE MakeUppercase(VAR S : String);
  31.  
  32. IMPLEMENTATION
  33.  
  34.   PROCEDURE MakeUppercase(VAR S : String); ASSEMBLER;
  35.   ASM
  36.     LES   DI,S
  37.     MOV   CL,ES:[DI]
  38.     AND   CX,00FFh
  39.     JZ    @@Done
  40.     MOV   BX,Offset Upper
  41.   @@Loop:
  42.     INC   DI
  43.     MOV   AL,ES:[DI]
  44.     XLAT
  45.     MOV   ES:[DI],AL
  46.     DEC   CX
  47.     JNZ   @@Loop
  48.   @@Done:
  49.   END;
  50.  
  51. {-Non Interfaced Routines (Initialise translation table)------------}
  52.  
  53.   FUNCTION DosMajorVersion : Byte;
  54.     {-Return DOS Major Version Number}
  55.   INLINE(
  56.     $B4/$30/  {mov ah,$30}
  57.     $CD/$21); {int $21}
  58.  
  59.   PROCEDURE SetCountrySpecificUppercase;
  60.     {-Convert 'Upper' into its country specific uppercase equivalent}
  61.   INLINE(
  62.     $BA/>Upper/ {mov dx,Upper}
  63.     $B9/>256/   {mov cx,256}
  64.     $B8/>$6521/ {mov ax,$6521}
  65.     $CD/$21);   {int $21}
  66.  
  67.   PROCEDURE InitialiseCaseConversion;
  68.   VAR
  69.     C : Char;
  70.   BEGIN
  71.     FOR C := #0 TO #255 DO
  72.       Upper[C] := C;
  73.     IF DosMajorVersion < 4 THEN
  74.       FOR C := #0 TO #255 DO
  75.         Upper[C] := System.UpCase(C) {Use Standard Case Conversion}
  76.     ELSE
  77.       SetCountrySpecificUppercase; {Use International Case Conversion}
  78.   END; {InitialiseCaseConversion}
  79.  
  80. {=Unit Initialisation==============================================}
  81.  
  82. BEGIN
  83.   InitialiseCaseConversion;
  84. END.
  85.